package com.limanyik.family.common.utils;

/**
 * 统一返回JSON
 *
 * @param <T>
 */
public class FamilyHttpResponse<T> {

    /**
     * 返回编码
     */
    private Integer code;
    /**
     * 返回消息
     */
    private String msg;
    /**
     * 消息类型（system：系统内部类型）（client：外部业务类型）
     */
    private String msgType = "client";
    /**
     * 消息内容
     */
    private T data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getMsgType() {
        return msgType;
    }

    public void setMsgType(String msgType) {
        this.msgType = msgType;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    FamilyHttpResponse() {
    }

    FamilyHttpResponse(Integer code) {
        this.code = code;
    }

    FamilyHttpResponse(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    FamilyHttpResponse(Integer code, String msg, String msgType) {
        this.code = code;
        this.msg = msg;
        this.msgType = msgType;
    }

    FamilyHttpResponse(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    FamilyHttpResponse(Integer code, String msg, String msgType, T data) {
        this.code = code;
        this.msg = msg;
        this.msgType = msgType;
        this.data = data;
    }

    public static <T> FamilyHttpResponse success() {
        return new FamilyHttpResponse(200, "成功");
    }

    public static <T> FamilyHttpResponse success(T data) {
        return new FamilyHttpResponse(200, "成功", data);
    }

    public static <T> FamilyHttpResponse error(String msg) {
        return new FamilyHttpResponse(500, msg);
    }

    public static <T> FamilyHttpResponse error(Integer code) {
        return new FamilyHttpResponse(code);
    }

    public static <T> FamilyHttpResponse error(Integer code, String msg) {
        return new FamilyHttpResponse(code, msg);
    }

    public static <T> FamilyHttpResponse error(Integer code, String msg, String msgType) {
        return new FamilyHttpResponse(code, msg, msgType);
    }

}
